/*
   Loads the right columns info for a selected folder/node
 */
function showGroupInfo(id){
    //hide confirmation dialogs
    hide('confirm');
    
    (new AjaxRequest).send({
		url			: urlBase+"action=getGroupInfo",
		data		: {
			id : id
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("userInfo").innerHTML = data["html"];
		}
	});
}


function showUserInfo(id){
    //hide confirmation dialogs
    hide('confirm');
    
    (new AjaxRequest).send({
		url			: urlBase+"action=getUserInfo",
		data		: {
			id : id
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("userInfo").innerHTML = data["html"];
		}
	});
}

/*
    Delete a group
*/
function dropGroup(id,message){
    if(confirm(message)){   
        
        var www = document.getElementById("members_1000");
        www.innerHTML = www.innerHTML + document.getElementById("members_"+id).innerHTML;
        document.getElementById("members_"+id).innerHTML = "n/a";
        document.getElementById("group_"+id+"_title").innerHTML = document.getElementById("group_"+id+"_name").innerHTML;
        document.getElementById("group_"+id+"_data").style.textDecoration = "line-through";
        
        (new AjaxRequest).send({
    		url			: urlBase+"action=deleteGroup",
    		data		: {
    			id : id
    		},
    		
    		onSuccess	: function(data, info)
    		{
    			document.getElementById("userInfo").innerHTML = data["html"];
    		}
    	});
    }
    return false;
}

/*
    Delete a user
*/
function dropUser(id,message){
    if(confirm(message)){   
        document.getElementById("user_"+id).style.display = "none";
        
        (new AjaxRequest).send({
    		url			: urlBase+"action=deleteUser",
    		data		: {
    			id : id
    		},
    		
    		onSuccess	: function(data, info)
    		{
    			document.getElementById("userInfo").innerHTML = data["html"];
    		}
    	});
    }
    return false;
}



/*
    Updating User's Name
*/
function updateUserName(id){
    var elem = document.getElementById("userName");
    var tempData = elem.innerHTML;
    elem.innerHTML = "<input type=\"text\" value=\""+tempData+"\" class=\"updateText\" onkeypress=\"return checkUserEnter(this,event,"+id+")\" onblur=\"return checkUserBlur(this,"+id+")\" />";   
    elem.style.backgroundColor = "#ffffcc";
    elem.firstChild.focus();
}


function checkUserEnter(elem,evt,id){
    evt = (evt) ? evt : window.event;

	if (evt.keyCode == 13) {	// pressed enter!
		ajaxUpdateUserName(id,elem.value);
		return false;
	} else {
		return true;
	}
}


function checkUserBlur(elem,id){
    ajaxUpdateUserName(id,elem.value);
	return false;
}


function ajaxUpdateUserName(id,value){
    (new AjaxRequest).send({
		url			: urlBase+"action=updateUserName",
		data		: {
			id : id,
			value: value
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("userName").innerHTML = data["html"];
			Fat.fade_element("userName",10,1000,"#ffffcc","#ffffff");
		}
	});   
}


/*
    Updating User's E-Mail
*/
function updateUserMail(id){
    var elem = document.getElementById("userMail");
    var tempData = elem.innerHTML;
    elem.innerHTML = "<input type=\"text\" value=\""+tempData+"\" class=\"updateText\" onkeypress=\"return checkMailEnter(this,event,"+id+")\" onblur=\"return checkMailBlur(this,"+id+")\" />";   
    elem.style.backgroundColor = "#ffffcc";
    elem.firstChild.focus();
}


function checkMailEnter(elem,evt,id){
    evt = (evt) ? evt : window.event;

	if (evt.keyCode == 13) {	// pressed enter!
		ajaxUpdateUserMail(id,elem.value);
		return false;
	} else {
		return true;
	}
}


function checkMailBlur(elem,id){
    ajaxUpdateUserMail(id,elem.value);
	return false;
}


function ajaxUpdateUserMail(id,value){
    (new AjaxRequest).send({
		url			: urlBase+"action=updateUserMail",
		data		: {
			id : id,
			value: value
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("userMail").innerHTML = data["html"];
			Fat.fade_element("userMail",10,1000,"#ffffcc","#ffffff");
		}
	});   
}


/*
    Updating Group Name
*/
function updateGroupName(id){
    var elem = document.getElementById("groupName");
    var tempData = elem.innerHTML;
    elem.innerHTML = "<input type=\"text\" value=\""+tempData+"\" id=\"groupTitle\" class=\"updateText\" onkeypress=\"return checkGroupEnter(this,event,"+id+")\" onkeyup=\"updateGroupInfo("+id+")\" onblur=\"return checkGroupBlur(this,"+id+")\" />";   
    elem.style.backgroundColor = "#ffffcc";
    elem.firstChild.focus();
}

function checkGroupEnter(elem,evt,id){
    evt = (evt) ? evt : window.event;
    
	if (evt.keyCode == 13) {	// pressed enter!
		ajaxUpdateGroupName(id,elem.value);
		return false;
	} else {
		return true;
	}
}

function checkGroupBlur(elem,id){
    ajaxUpdateGroupName(id,elem.value);
	return false;
}

function ajaxUpdateGroupName(id,value){
    (new AjaxRequest).send({
		url			: urlBase+"action=updateGroupName",
		data		: {
			id : id,
			value: value
		},
		
		onSuccess	: function(data, info)
		{
			document.getElementById("groupName").innerHTML = data["html"];
			Fat.fade_element("groupName",10,1000,"#ffffcc","#ffffff");
		}
	});   
}

function updateGroupInfo(id){
	//rephare the info dings
	var el = document.getElementById("group_"+id+"_name");
	var e2 = document.getElementById("groupTitle");
	el.innerHTML = e2.value;
	return false;
}